/*
 * File Name:               XCacheDataManager.cs
 * 
 * Description:             普通类
 * Author:                  lisiyu <576603306@qq.com>
 * Create Date:             2017/01/18
 */

using System;
using System.Collections.Generic;

public class XCacheDataManager<T>
{
    private Dictionary<T, ICacheData> mCacheDatas = new Dictionary<T, ICacheData>();
    public void add<K>(T key, Func<K> callback)
    {
        if (mCacheDatas.ContainsKey(key))
            return;

        mCacheDatas.Add(key, new XCacheData<K>(callback));
    }

    public K get<K>(T key)
    {
        return (mCacheDatas[key] as XCacheData<K>).getValue();
    }

    public void reset()
    {
        var itor = mCacheDatas.GetEnumerator();
        while (itor.MoveNext())
        {
            itor.Current.Value.reset();
        }
    }
}
